import time
from appium import webdriver
from appium.options.android import UiAutomator2Options
from page.main import Main
from page.base_page import Basepage
from appium.webdriver.common.appiumby import AppiumBy as by


class App(Basepage):
    def start(self):
        if self.driver is None:
            android_options = UiAutomator2Options()
            android_options.set_capability("platformName", "Android")
            android_options.set_capability("platformVersion", "7.1.2")
            android_options.set_capability("deviceName", "SM_N976N")
            android_options.set_capability("appPackage", "com.kuke")
            android_options.set_capability("appActivity", "module_business_splash.ui.SplashActivity")
            android_options.set_capability("app", "E:\\test\\kkwx_7222.apk")
            android_options.set_capability("noReset", False)
            android_options.set_capability("unicodeKeyboard", True)
            android_options.set_capability("resetKeyboard", True)
            android_options.set_capability("device", "d2q")

            self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', options=android_options)
        else:
            self.driver.start_activity("com.kuke", "module_business_splash.ui.SplashActivity")
        return self

    def main(self):
        return Main(self.driver)

    def agree(self):
        return self.find_and_click('App', 'agree')

    def skip(self):
        return self.find_and_click('App', 'skip')

    def close(self):
        return self.find_and_click('App', 'close')

    def queren(self):
        return self.find_and_click('App', 'queren')

